class Container {
    static of (value) {
        return new Container(value);
    }
    constructor (value) {
        this._value = value;
    }
    map(fn) {
        return Container.of(fn(this._value));
    }
}

class MayBe {
    static of(value) {
        return new MayBe(value);
    }

    constructor(value) {
        this._value = value;
    }

    map(fn) {
        // return MayBe.of(fn(this._value));
        return this.isNothing() ? this : MayBe.of(fn(this._value));
    }
    
    isNothing() {
        return this._value === null || this._value === undefined;
    }
}


const fp = require('lodash/fp');

const xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);

const ex2 = function(value) {
    return fp.first(value);
};

console.log('ex2', xs.map(ex2));